package com.ksyun.campus.client.domain;

/**
 * 副本信息类
 * 用于表示数据块在数据服务器上的副本信息
 */
public class ReplicaInfo {
    private String dsId;    // 数据服务器ID
    private String host;    // 主机地址
    private int port;       // 端口号
    private String role;    // 角色（如主副本、从副本等）
    
    // 默认构造函数
    public ReplicaInfo() {}
    
    // 带参数构造函数
    public ReplicaInfo(String dsId, String host, int port, String role) {
        this.dsId = dsId;
        this.host = host;
        this.port = port;
        this.role = role;
    }
    
    // Getter 和 Setter 方法
    public String getDsId() {
        return dsId;
    }
    
    public void setDsId(String dsId) {
        this.dsId = dsId;
    }
    
    public String getHost() {
        return host;
    }
    
    public void setHost(String host) {
        this.host = host;
    }
    
    public int getPort() {
        return port;
    }
    
    public void setPort(int port) {
        this.port = port;
    }
    
    public String getRole() {
        return role;
    }
    
    public void setRole(String role) {
        this.role = role;
    }
    
    @Override
    public String toString() {
        return "ReplicaInfo{" +
                "dsId='" + dsId + '\'' +
                ", host='" + host + '\'' +
                ", port=" + port +
                ", role='" + role + '\'' +
                '}';
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        
        ReplicaInfo that = (ReplicaInfo) o;
        
        if (port != that.port) return false;
        if (dsId != null ? !dsId.equals(that.dsId) : that.dsId != null) return false;
        if (host != null ? !host.equals(that.host) : that.host != null) return false;
        return role != null ? role.equals(that.role) : that.role != null;
    }
    
    @Override
    public int hashCode() {
        int result = dsId != null ? dsId.hashCode() : 0;
        result = 31 * result + (host != null ? host.hashCode() : 0);
        result = 31 * result + port;
        result = 31 * result + (role != null ? role.hashCode() : 0);
        return result;
    }
}
